package ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import td.FireTrap;

/*
 * View class to represent Fire Traps on the map.
 * */
public class FireTrapView extends TrapView {

	public FireTrapView(FireTrap ft) {
		super(ft);
		this.setLayout(new GridBagLayout());
		/*Sets the displayable image.*/
		image = Toolkit.getDefaultToolkit().getImage("Images/firetrap.png");
		update();
	}

	@Override
	public void update() {
		this.removeAll();
		GridBagConstraints gridc = new GridBagConstraints();
		/*Checks if the trap has an upgrade stone, and sets it's image*/
		if (((FireTrap) fieldElement).wasUpgraded) {
			gridc.gridx = 0;
			gridc.gridy = 0;
			gridc.anchor = GridBagConstraints.LAST_LINE_END;
			Image stone = null;
			switch(((FireTrap) fieldElement).stone){
			case Blue:
				stone = Toolkit.getDefaultToolkit().getImage("Images/blue.png");
				break;
			case Red:
				stone = Toolkit.getDefaultToolkit().getImage("Images/red.png");
				break;
			case Yellow:
				stone = Toolkit.getDefaultToolkit().getImage("Images/yellow.png");
				break;
			case Rainbow:
				stone = Toolkit.getDefaultToolkit().getImage("Images/rainbow.png");
				break;
			}
			JLabel picLabel = new JLabel(new ImageIcon(stone));
			add(picLabel, gridc);
		}
		/*Puts up picture of the trap*/
		JLabel picLabel = new JLabel(new ImageIcon(image));
		gridc.gridx = 0;
		gridc.gridy = 0;
		gridc.anchor = GridBagConstraints.CENTER;
		add(picLabel, gridc);
	}
}
